<template>
  <div>
    <el-dialog
      v-el-drag-dialog
      title="修改"
      :close-on-click-modal="false"
      :visible.sync="visible"
      width="55%">
      <el-form :model="dataForm" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
        <el-row :gutter="20">
          <el-col :span="10">
            <el-form-item label="注册时间:">
              <span>{{dataForm.addTime}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="营业时间:">
              <el-input v-model="dataForm.msn" placeholder="营业时间" style="width: 250px"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="10">
            <el-form-item label="会员名称:">
              <el-input v-model="dataForm.trueName" placeholder="会员名称"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="会员账户:">
              <el-input v-model="dataForm.userName" placeholder="会员账户"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="10">
            <el-form-item label="会员真名:">
              <el-input v-model="dataForm.realName" placeholder="会员真名"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="会员类型:">
              <span>{{memberType[dataForm.userType]}}</span>&nbsp;&nbsp;&nbsp;
              <a><i class="el-icon-edit" @click="updateUserType()" v-show="this.dataForm.userType !== 1"></i></a>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="10">
            <el-form-item label="会员手机:">
              <el-input v-model="dataForm.mobile" placeholder="会员手机"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="审核意见:">
              <el-input v-model="dataForm.checkComment" placeholder="审核意见" ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="10">
            <el-form-item label="会员主图:">
              <el-upload
              :action="this.$http.adornUrl(`/user/business/uploadImg?token=${this.$cookie.get('token')}`)"
              list-type="picture-card"
              :file-list="dataForm.mainImgSrc"
              :on-preview="handlePreview"
              :on-success="handleSuccess"
              :on-remove="handleRemove"
              :on-exceed="onExceed"
              :limit="1">
              <i class="el-icon-plus"></i>
              </el-upload>
              <el-dialog :visible.sync="dialogVisible">
                <img width="100%" :src="dialogImageUrl" alt="">
              </el-dialog>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="营业证件:">
              <el-upload
              :action="this.$http.adornUrl(`/user/business/uploadImg?token=${this.$cookie.get('token')}`)"
              list-type="picture-card"
              :file-list="dataForm.licensePic"
              :on-preview="handlePreview"
              :on-success="handleSuccess1"
              :on-remove="handleRemove1"
              :on-exceed="onExceed1"
              :limit="1">
              <i class="el-icon-plus"></i>
              </el-upload>
              <el-dialog :visible.sync="dialogVisible">
                <img width="100%" :src="dialogImageUrl" alt="">
              </el-dialog>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="10">
            <el-form-item label="会员地址:">
              <el-input v-model="dataForm.address" placeholder="会员地址"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="会员描述:">
              <el-input v-model="dataForm.description" placeholder="会员描述"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="10">
            <el-form-item label="余额:">
              <span>{{dataForm.integral}}（现金券）</span>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="余额:">
              <span>{{dataForm.commissionMoney}}（推广）</span>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item label="总金额:">
              <span>{{dataForm.balanceMoney===''?0:dataForm.balanceMoney}}(元)</span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="未提现:">
              <span>{{dataForm.notExtract===''?0:dataForm.notExtract}}（元）</span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="已提现:">
              <span>{{dataForm.yesExtract===''?0:dataForm.yesExtract}}（元）</span>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="上级名称:">
              <span>{{dataForm.panUserTrueName}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="上级账号:">
              <span>{{dataForm.panUserName}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="上级类型:">
              <span>{{memberType[dataForm.panUserType]}}</span>
            </el-form-item>
        </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col>
            <span>所在区域：</span>
            <el-select v-model="dataForm.provinceId" placeholder="请选择省" @change="provinceChanged">
              <el-option 
                v-for="item in dataForm.provinceList"
                :key="item.id"
                :label="item.areaName"
                :value="item.id">
              </el-option>
            </el-select>
            <el-select v-model="dataForm.cityId" placeholder="请选择市" @change="provinceChanged1">
              <el-option 
                v-for="item in dataForm.cityList"
                :key="item.id"
                :label="item.areaName"
                :value="item.id">
              </el-option>
            </el-select>
            <el-select v-model="dataForm.areaId" placeholder="请选择区">
              <el-option 
                v-for="item in dataForm.areaList"
                :key="item.id"
                :label="item.areaName"
                :value="item.id">
              </el-option>
            </el-select>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <br/>
          <el-col :span="10">
            <span>状态：</span>
            <el-radio v-model="dataForm.state" label="0">正常</el-radio>
            <el-radio v-model="dataForm.state" label="1">锁定</el-radio>
          </el-col>
          <el-col :span="10">
            <span>性别：</span>
            <el-radio v-model="dataForm.sex" label="1">男</el-radio>
            <el-radio v-model="dataForm.sex" label="0">女</el-radio>
          </el-col>
        </el-row>
        <el-row>
          <br/>
          <el-col :span="30">
            <el-form-item label="是否开通超级大玩家:" prop="report" label-width="150px">
              <el-select v-model="dataForm.report" placeholder="是否开通超级大玩家">
                <el-option
                v-for="type in dataForm.reportList"
                :key="type.value"
                :label="type.label"
                :value="type.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <br/>
          <el-col :span="10">
            <el-form-item label="密码:">
              <el-input v-model="dataForm.password" placeholder="密码"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="电子邮箱:">
              <el-input v-model="dataForm.email" placeholder="电子邮箱"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancel()">取消</el-button>
        <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
      </span>
    </el-dialog>

    <el-dialog
      v-el-drag-dialog
      title="修改用户类型"
      :close-on-click-modal="false"
      width="50%"
      :visible.sync="userTypeVisible">
      <el-form :model="userTypeForm" ref="userTypeForm" :rules="rules" @keyup.enter.native="userTypeFormSubmit()" label-width="80px">
        <el-row :gutter="20">
          <el-col :span="10">
            <el-form-item label="用户名称:">
              <span>{{dataForm.userName}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="用户类型:">
              <el-select v-model="dataForm.userType" placeholder="请选择" :value="dataForm.userType">
                <!-- <el-option
                  v-for="type in typeNameList"
                  :key="type.val"
                  :label="type.label"
                  :value="type.val">
                </el-option> -->
                <el-option 
                  v-for="item in dataForm.userTypeOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
                <!-- <span v-if="dataForm.userTypes == 1">
                  <el-option 
                  v-for="item in dataForm.userTypeOptions1"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
                </span>
                <span v-if="dataForm.userTypes == 2">
                  <el-option 
                  v-for="item in dataForm.userTypeOptions2"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
                </span>
                <span v-if="dataForm.userTypes == 4">
                  <el-option 
                  v-for="item in dataForm.userTypeOptions4"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
                </span>
                <span v-if="dataForm.userTypes == 5">
                  <el-option 
                  v-for="item in dataForm.userTypeOptions5"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
                </span>
                <span v-if="dataForm.userTypes == 6">
                  <el-option 
                  v-for="item in dataForm.userTypeOptions6"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
                </span>
                <span v-if="dataForm.userTypes == 7">
                  <el-option 
                  v-for="item in dataForm.userTypeOptions7"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
                </span>
                <span v-if="dataForm.userTypes == 8">
                  <el-option 
                  v-for="item in dataForm.userTypeOptions8"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
                </span> -->
              </el-select>
            </el-form-item>

          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="10">
            <el-form-item label="选择操作:" prop="moneyType">
              <el-radio v-model="userTypeForm.moneyType" label="5" border>升级</el-radio>
              <el-radio v-model="userTypeForm.moneyType" label="4" border>降级</el-radio>
            </el-form-item>
          </el-col>
          <!-- <el-col :span="10">
            <el-form-item label="支付金额" prop="upgradeMoney">
              <el-input v-model="userTypeForm.upgradeMoney" :disabled="userTypeForm.moneyType === `4`"></el-input>
            </el-form-item>
          </el-col> -->
          <el-col :span="10">
          <el-form-item label="绑定上级" v-show="this.updateUserTypeVisible">
              <el-select v-model="dataForm.superiorId" filterable placeholder="请选择">
              <el-option
                v-for="item in this.allOperator"
                :key="item.id"
                :label="item.userName"
                :value="item.id">
              </el-option>
            </el-select>
            </el-form-item>
            </el-col>
        </el-row>

        <el-row :gutter="20">
          <!-- <el-col :span="10">
            <el-form-item label="是否返券:" prop="isCommission">
              <el-radio v-model="userTypeForm.isCommission" label="1" border>返券</el-radio>
              <el-radio v-model="userTypeForm.isCommission" label="0" border>不返券</el-radio>
            </el-form-item>
          </el-col> -->
          <el-col :span="10">
            <!-- <el-form-item label="赠送金额" prop="givingIntegral">
              <el-input v-model="userTypeForm.givingIntegral" :disabled="userTypeForm.isCommission === `0`"></el-input>
            </el-form-item> -->
          </el-col>
        </el-row>
      </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="userTypeVisible = false">取消</el-button>
          <el-button type="primary" @click="userTypeFormSubmit()">确定</el-button>
        </span>
    </el-dialog>
  </div>
</template>

<script>
  import {typeNameList, typeName} from '@/utils/memberType'
  export default {
    data: function () {
      const checkNum = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('不能为空'))
        }
        const reg = /^(^[1-9](\d+)?(\.\d{1,2})?$)|(^0$)|(^\d\.\d{1,}$)$/
        if (!reg.test(value)) {
          return callback(new Error('不合法的数据'))
        }
      }
      return {
        visible: false,
        userTypeVisible: false,
        typeNameList: typeNameList,
        memberType: typeName,
        allOperator: [],
        updateUserTypeVisible: false,
        userTypeForm: {
          moneyType: '5',
          upgradeMoney: 0, // 支付金额
          isCommission: '0', // 是否返券
          givingIntegral: 0 // 赠送现金券
        },
        dialogImageUrl: '',
        dialogVisible: false,
        dataForm: {
          id: 0,
          trueName: '',
          msn: '',
          userName: '',
          realName: '',
          userType: '',
          photoId: '',
          commissionMoney: '',
          notExtract: '',
          yesExtract: '',
          balanceMoney: '',
          integral: '',
          checkComment: '',
          licensePic: [],
          address: '',
          addTime: '',
          panUserTrueName: '',
          panUserName: '',
          panUserType: '',
          userTypes: '',
          provinceId: '',
          province: '',
          provinceList: [],
          cityId: '',
          city: '',
          cityList: [],
          areaId: '',
          area: '',
          areaList: [],
          status: '',
          sex: '',
          email: '',
          password: '',
          licenseImg: '',
          mainImgPath: '',
          mainImgName: '',
          report: '',
          mobile: '',
          mainImgSrc: [],
          state: '',
          superiorId: '',
          userTypeOptions: [{
            value: 2,
            label: '普通联盟店'
          }, {
            value: 3,
            label: '消费者'
          }, {
            value: 4,
            label: 'VIP会员'
          }, {
            value: 5,
            label: '中级版联盟店'
          }, {
            value: 6,
            label: '高级版联盟店'
          }, {
            value: 7,
            label: '城市合伙人'
          }, {
            value: 8,
            label: '城市合伙人联盟店'
          }],
          reportList: [{
            value: 0,
            label: '否'
          }, {
            value: 1,
            label: '是'
          }]
        },
        rules: {
          upgradeMoney: [
            { validator: checkNum, required: true, trigger: 'blur' }
          ],
          givingIntegral: [
            { validator: checkNum, required: true, trigger: 'blur' }
          ],
          email: [
            { required: true, message: '邮箱不合规范', trigger: 'blur' },
            { pattern: /^([0-9A-Za-z\-_.]+)@([0-9a-z]+\.[a-z]{2,3}(\.[a-z]{2})?)$/g, message: '邮箱不合规范', trigger: 'blur' }
          ],
          password: [
            { required: true, message: '4到16位（字母，数字，下划线，减号）', trigger: 'blur' },
            { pattern: /^[a-zA-Z0-9_-]{4,16}$/, message: '4到16位（字母，数字，下划线，减号）', trigger: 'blur' }
          ]
        }
      }
    },
    watch: {
      'userTypeForm.moneyType': function (val) {
        if (val === '4') {
          this.updateUserTypeVisible = false
          // 降级判断可选类型
          // 如果当前是合伙人
          if (this.dataForm.userType === 7 || this.dataForm.userType === 8) {
            this.dataForm.userTypeOptions = [{value: 2, label: '普通联盟店'}, {value: 3, label: '消费者'}, {value: 4, label: 'VIP'}, {value: 5, label: '中级版联盟店'}, {value: 6, label: '高级版联盟店'}, {value: 7, label: '城市合伙人'}, {value: 8, label: '城市合伙人联盟店'}]
          } else if (this.dataForm.userType === 6) {
            this.dataForm.userTypeOptions = [{value: 2, label: '普通联盟店'}, {value: 3, label: '消费者'}, {value: 4, label: 'VIP'}, {value: 5, label: '中级版联盟店'}, {value: 6, label: '高级版联盟店'}]
          } else if (this.dataForm.userType === 5) {
            this.dataForm.userTypeOptions = [{value: 2, label: '普通联盟店'}, {value: 3, label: '消费者'}, {value: 4, label: 'VIP'}, {value: 5, label: '中级版联盟店'}]
          } else if (this.dataForm.userType === 2) {
            this.dataForm.userTypeOptions = [{value: 2, label: '普通联盟店'}, {value: 3, label: '消费者'}, {value: 4, label: 'VIP'}]
          } else if (this.dataForm.userType === 4) {
            this.dataForm.userTypeOptions = [{value: 3, label: '消费者'}, {value: 4, label: 'VIP'}]
          } else {
            this.dataForm.userTypeOptions = [{value: 3, label: '消费者'}]
          }
        } else {
          this.updateUserType()
          // 升级类型可选
          if (this.dataForm.userType === 3) {
            this.dataForm.userTypeOptions = [{value: 2, label: '普通联盟店'}, {value: 3, label: '消费者'}, {value: 4, label: 'VIP'}, {value: 5, label: '中级版联盟店'}, {value: 6, label: '高级版联盟店'}, {value: 7, label: '城市合伙人'}, {value: 8, label: '城市合伙人联盟店'}]
          } else if (this.dataForm.userType === 4) {
            this.dataForm.userTypeOptions = [{value: 2, label: '普通联盟店'}, {value: 4, label: 'VIP'}, {value: 5, label: '中级版联盟店'}, {value: 6, label: '高级版联盟店'}, {value: 7, label: '城市合伙人'}, {value: 8, label: '城市合伙人联盟店'}]
          } else if (this.dataForm.userType === 2) {
            this.dataForm.userTypeOptions = [{value: 2, label: '普通联盟店'}, {value: 5, label: '中级版联盟店'}, {value: 6, label: '高级版联盟店'}, {value: 7, label: '城市合伙人'}, {value: 8, label: '城市合伙人联盟店'}]
          } else if (this.dataForm.userType === 5) {
            this.dataForm.userTypeOptions = [{value: 5, label: '中级版联盟店'}, {value: 6, label: '高级版联盟店'}, {value: 7, label: '城市合伙人'}, {value: 8, label: '城市合伙人联盟店'}]
          } else if (this.dataForm.userType === 6) {
            this.dataForm.userTypeOptions = [{value: 6, label: '高级版联盟店'}, {value: 7, label: '城市合伙人'}, {value: 8, label: '城市合伙人联盟店'}]
          } else {
            this.dataForm.userTypeOptions = [{value: 7, label: '城市合伙人'}, {value: 8, label: '城市合伙人联盟店'}]
          }
        }
      }
    },
    methods: {
      // 图片预览
      handlePreview (file) {
        this.dialogImageUrl = file.url
        this.dialogVisible = true
      },
       // 文件上传成功的钩子函数
      handleSuccess (res, file, fileList) {
        this.$message({
          type: 'info',
          message: '图片上传成功',
          duration: 6000
        })
        if (res.code === 0) {
          this.dataForm.mainImgSrc.push({name: 'tupian', url: 'http://image.yilianbaihui.cn/consumer/business/' + res.data})
          this.dataForm.mainImgPath = 'business'
          this.dataForm.mainImgName = res.data
        }
      },
      // 删除文件之前的钩子函数
      handleRemove (file, fileList) {
        for (var i = 0; i < this.dataForm.mainImgSrc.length; i++) {
          var picc = this.dataForm.mainImgSrc[i]
          if (picc.url === file.url) {
            this.dataForm.mainImgSrc.splice(i, 1)
            this.dataForm.mainImg = ''
          }
        }
        this.$message({
          type: 'info',
          message: '已删除原有图片',
          duration: 6000
        })
      },
      // 上传的文件个数超出设定时触发的函数
      onExceed (files, fileList) {
        this.$message({
          type: 'info',
          message: '最多只能上传1个图片',
          duration: 6000
        })
      },
       // 文件上传成功的钩子函数
      handleSuccess1 (res, file, fileList) {
        this.$message({
          type: 'info',
          message: '图片上传成功',
          duration: 6000
        })
        if (res.code === 0) {
          this.dataForm.licensePic.push({name: 'tupian', url: 'http://image.yilianbaihui.cn/consumer/business/' + res.data})
          this.dataForm.licenseImg = 'business/' + res.data
          debugger
        }
      },
      // 删除文件之前的钩子函数
      handleRemove1 (file, fileList) {
        for (var i = 0; i < this.dataForm.licensePic.length; i++) {
          var picc = this.dataForm.licensePic[i]
          if (picc.url === file.url) {
            this.dataForm.licensePic.splice(i, 1)
            this.dataForm.licenseImg = ''
          }
        }
        this.$message({
          type: 'info',
          message: '已删除原有图片',
          duration: 6000
        })
      },
      // 上传的文件个数超出设定时触发的函数
      onExceed1 (files, fileList) {
        this.$message({
          type: 'info',
          message: '最多只能上传1个图片',
          duration: 6000
        })
      },
      init (id) {
        this.dataForm.updateFrontType = ''
        this.updateUserTypeVisible = false
        this.dataForm.superiorId = ''
        this.dataForm.mainImgPath = ''
        this.dataForm.mainImgName = ''
        this.dataForm.licenseImg = ''
        this.dataForm.mainImgSrc = []
        this.dataForm.licensePic = []
        this.dataForm.id = id || 0
        this.dataForm.mobile = ''
        this.visible = true
        this.$nextTick(() => {
          // this.$refs['dataForm'].resetFields()
          // 查询出所有省
          this.dataListLoading = true
          this.$http({
            url: this.$http.adornUrl('/member/area/queryProvinceList'),
            method: 'post'
          }).then(({data}) => {
            this.dataForm.provinceList = data.data
          })
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/member/user/getUserById/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.id = data.data.id
                this.dataForm.msn = data.data.msn
                this.dataForm.balanceMoney = data.data.balanceMoney
                this.dataForm.trueName = data.data.trueName
                this.dataForm.userName = data.data.userName
                this.dataForm.realName = data.data.realName
                // this.dataForm.userType = this.typeNameList[data.memberVO.userType].label
                this.dataForm.userType = data.data.userType
                this.dataForm.photoId = data.data.photoId
                this.dataForm.commissionMoney = data.data.commissionMoney
                this.dataForm.notExtract = data.data.notExtract
                this.dataForm.yesExtract = data.data.yesExtract
                this.dataForm.integral = data.data.integral
                this.dataForm.checkComment = data.data.checkComment
                // this.dataForm.licensePic = data.data.licensePic
                if (data.data.licensePic !== '' && data.data.licensePic != null) {
                  let pics = data.data.licensePic
                  this.dataForm.licensePic.push({name: 'tupian', url: 'http://image.yilianbaihui.cn/consumer/' + pics})
                  this.dataForm.licenseImg = data.data.licensePic
                }
                if (data.data.path !== null && data.data.path !== '' && data.data.name !== null && data.data.path !== '') {
                  let pic = data.data.path + '/' + data.data.name
                  this.dataForm.mainImgSrc.push({name: 'tupian', url: 'http://image.yilianbaihui.cn/consumer/' + pic})
                  this.dataForm.mainImgPath = data.data.path
                  this.dataForm.mainImgName = data.data.name
                }
                if (data.data.path !== null && data.data.path !== '' && data.data.name == null) {
                  let pic = data.data.path
                  this.dataForm.mainImgSrc.push({name: 'tupian', url: 'http://image.yilianbaihui.cn/consumer/' + pic})
                  this.dataForm.mainImgPath = pic
                  this.dataForm.mainImgName = ''
                }
                this.dataForm.address = data.data.address
                this.dataForm.addTime = data.data.addTime
                this.dataForm.panUserTrueName = data.data.panUserTrueName
                this.dataForm.panUserName = data.data.panUserName
                this.dataForm.panUserType = data.data.panUserType
                this.dataForm.userTypes = data.data.userTypes
                this.dataForm.provinceId = data.data.provinceId
                this.dataForm.province = data.data.province
                // this.dataForm.provinceList.push({id: data.data.provinceId, name: data.data.province})
                this.dataForm.cityId = data.data.cityId
                this.dataForm.city = data.data.city
                // this.dataForm.cityList.push({id: data.data.cityId, name: data.data.city})
                this.dataForm.areaId = data.data.areaId
                this.dataForm.area = data.data.area
                // this.dataForm.areaList.push({id: data.data.areaId, name: data.data.area})
                if (this.dataForm.cityId != null && this.dataForm.city != null) {
                  this.dataForm.cityList = [{id: this.dataForm.cityId, areaName: this.dataForm.city}]
                }
                if (this.dataForm.areaId != null && this.dataForm.area != null) {
                  this.dataForm.areaList = [{id: this.dataForm.areaId, areaName: this.dataForm.area}]
                }
                this.dataForm.report = data.data.report
                this.dataForm.mobile = data.data.mobile
                this.dataForm.state = data.data.state + ''
                this.dataForm.sex = data.data.sex + ''
                this.dataForm.email = data.data.email
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        console.log(this.dataForm.province)
        console.log(this.dataForm.city)
        console.log(this.dataForm.area)
        console.log(this.dataForm.photoId)
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/member/user/modifyById`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'MSN': this.dataForm.msn,
                'trueName': this.dataForm.trueName,
                'userName': this.dataForm.userName,
                'realName': this.dataForm.realName,
                'checkComment': this.dataForm.checkComment,
                'address': this.dataForm.address,
                'userType': this.dataForm.userType,
                'ststus': this.dataForm.status,
                'sex': this.dataForm.sex,
                'province': this.dataForm.provinceId,
                'city': this.dataForm.cityId,
                'area': this.dataForm.areaId,
                'email': this.dataForm.email,
                'password': this.dataForm.password,
                'mainImgPath': this.dataForm.mainImgPath,
                'mainImgName': this.dataForm.mainImgName,
                'licenseImg': this.dataForm.licenseImg,
                'photoId': this.dataForm.photoId,
                'report': this.dataForm.report,
                'mobile': this.dataForm.mobile,
                'state': this.dataForm.state
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      },
      cancel () {
        this.visible = false
        this.$emit('refreshDataList')
      },
      provinceChanged (id) {
        this.$http({
          url: this.$http.adornUrl('/member/area/querySubordinateList'),
          method: 'post',
          data: this.$http.adornData(id, false)
        }).then(({data}) => {
          this.dataForm.city = ''
          this.dataForm.area = ''
          this.dataForm.cityList = data.data
        })
      },
      provinceChanged1 (id) {
        this.$http({
          url: this.$http.adornUrl('/member/area/querySubordinateList'),
          method: 'post',
          data: this.$http.adornData(id, false)
        }).then(({data}) => {
          this.dataForm.area = ''
          this.dataForm.areaList = data.data
        })
      },
      userTypeFormSubmit () {
        if (this.updateUserTypeVisible) {
          if (this.dataForm.superiorId === '') {
            this.$message.error('请选择上级！')
            return
          }
        }
        this.$http({
          url: this.$http.adornUrl(`/member/user/updateUserType`),
          method: 'post',
          data: this.$http.adornData({
            'userId': this.dataForm.id || undefined,
            'upgradeUserType': this.dataForm.userType,
            'upgradeMoney': this.userTypeForm.upgradeMoney,
            'isCommission': this.userTypeForm.isCommission,
            'givingIntegral': this.userTypeForm.givingIntegral,
            'userType': this.dataForm.userType,
            'moneyType': this.userTypeForm.moneyType,
            'upgradeMobile': this.dataForm.mobile,
            'superiorId': this.dataForm.superiorId,
            'passiveUserType': this.dataForm.updateFrontType,
            'upgradeUserType': this.dataForm.userType
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.userTypeVisible = false
              }
            })
          } else {
            this.$message.error(data.msg)
          }
        })
      },
      updateUserType () {
        this.dataForm.updateFrontType = this.dataForm.userType
        this.userTypeVisible = true
        this.$http({
          url: this.$http.adornUrl(`/member/user/needToSelectSuperiorById/${this.dataForm.id}`),
          method: 'get',
          params: this.$http.adornParams()
        }).then(({data}) => {
          if (data && data.code === 0) {
            debugger
            console.log(data.data.userType)
            if (data.data.userType !== 1) {
              this.$http({
                url: this.$http.adornUrl(`/member/user/queryAllOperator`),
                method: 'get',
                params: this.$http.adornParams()
              }).then(({data}) => {
                if (data && data.code === 0) {
                  debugger
                  this.allOperator = data.data
                  this.updateUserTypeVisible = true
                }
              })
            }
          }
        })
        if (this.userTypeForm.moneyType === '4') {
          // 降级判断可选类型
          // 如果当前是合伙人
          if (this.dataForm.userType === 7 || this.dataForm.userType === 8) {
            this.dataForm.userTypeOptions = [{value: 2, label: '普通联盟店'}, {value: 3, label: '消费者'}, {value: 4, label: 'VIP'}, {value: 5, label: '中级版联盟店'}, {value: 6, label: '高级版联盟店'}, {value: 7, label: '城市合伙人'}, {value: 8, label: '城市合伙人联盟店'}]
          } else if (this.dataForm.userType === 6) {
            this.dataForm.userTypeOptions = [{value: 2, label: '普通联盟店'}, {value: 3, label: '消费者'}, {value: 4, label: 'VIP'}, {value: 5, label: '中级版联盟店'}, {value: 6, label: '高级版联盟店'}]
          } else if (this.dataForm.userType === 5) {
            this.dataForm.userTypeOptions = [{value: 2, label: '普通联盟店'}, {value: 3, label: '消费者'}, {value: 4, label: 'VIP'}, {value: 5, label: '中级版联盟店'}]
          } else if (this.dataForm.userType === 2) {
            this.dataForm.userTypeOptions = [{value: 2, label: '普通联盟店'}, {value: 3, label: '消费者'}, {value: 4, label: 'VIP'}]
          } else if (this.dataForm.userType === 4) {
            this.dataForm.userTypeOptions = [{value: 3, label: '消费者'}, {value: 4, label: 'VIP'}]
          } else {
            this.dataForm.userTypeOptions = [{value: 3, label: '消费者'}]
          }
        } else {
          // 升级类型可选
          if (this.dataForm.userType === 3) {
            this.dataForm.userTypeOptions = [{value: 2, label: '普通联盟店'}, {value: 3, label: '消费者'}, {value: 4, label: 'VIP'}, {value: 5, label: '中级版联盟店'}, {value: 6, label: '高级版联盟店'}, {value: 7, label: '城市合伙人'}, {value: 8, label: '城市合伙人联盟店'}]
          } else if (this.dataForm.userType === 4) {
            this.dataForm.userTypeOptions = [{value: 2, label: '普通联盟店'}, {value: 4, label: 'VIP'}, {value: 5, label: '中级版联盟店'}, {value: 6, label: '高级版联盟店'}, {value: 7, label: '城市合伙人'}, {value: 8, label: '城市合伙人联盟店'}]
          } else if (this.dataForm.userType === 2) {
            this.dataForm.userTypeOptions = [{value: 2, label: '普通联盟店'}, {value: 5, label: '中级版联盟店'}, {value: 6, label: '高级版联盟店'}, {value: 7, label: '城市合伙人'}, {value: 8, label: '城市合伙人联盟店'}]
          } else if (this.dataForm.userType === 5) {
            this.dataForm.userTypeOptions = [{value: 5, label: '中级版联盟店'}, {value: 6, label: '高级版联盟店'}, {value: 7, label: '城市合伙人'}, {value: 8, label: '城市合伙人联盟店'}]
          } else if (this.dataForm.userType === 6) {
            this.dataForm.userTypeOptions = [{value: 6, label: '高级版联盟店'}, {value: 7, label: '城市合伙人'}, {value: 8, label: '城市合伙人联盟店'}]
          } else {
            this.dataForm.userTypeOptions = [{value: 7, label: '城市合伙人'}, {value: 8, label: '城市合伙人联盟店'}]
          }
        }
      }
    }
  }
</script>
<style scoped>
  .el-input{
      width: 250px;
  }
</style>
